﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Web.group
{
    public partial class shareinview : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(Request["phonebookid"]))
            {
                throw new Base.CustomException("缺少参数phonebookid");
            }

            Hashtable phonebook = PhoneBook.Group.PhoneBook.get(Request["phonebookid"]);
            if (phonebook == null)
            {
                throw new Base.CustomException("参数phonebookid不正确");
            }

            Hashtable user = PhoneBook.Users.Users.get(Commons.StrUtil.FormatValue(Session["userid"]));
            Hashtable pbshare = PhoneBook.Group.PbShare.get(Request["phonebookid"], Commons.StrUtil.FormatValue(user["groupid"]));
            if (pbshare == null)
            {
                throw new Base.CustomException("无权限查看此通讯录");
            }

            SetDivePage(ref GridView1, ref GV);
            if (!IsPostBack)
            {
                foreach (DataControlField col in GridView1.Columns)
                {
                    BoundField bf = col as BoundField;
                    if (bf == null) continue;
                    ddl_tj.Items.Add(new ListItem(bf.HeaderText, bf.DataField));
                }
                QueryData();
            }
        }

        public override void QueryData()
        {

            Hashtable user = PhoneBook.Users.Users.get(Commons.StrUtil.FormatValue(Session["userid"]));
            DataSet ds = PhoneBook.Group.PbMember.querysharemember(Request["phonebookid"]);
            //绑定数据集
            string filter = string.Empty;
            if (!string.IsNullOrWhiteSpace(txb_keyword.Text))
            {
                filter = string.Format("{0} like '%{1}%'", ddl_tj.SelectedItem.Value, txb_keyword.Text);
                Commons.DataUtil.DataFilter(ds, filter, "");
            }

            GVDataBind(ref GridView1, ref GV, ds);
        }

        protected void btn_query_Click(object sender, EventArgs e)
        {
            QueryData();
        }

        protected void btn_export_Click(object sender, EventArgs e)
        {
            string filename = string.Format("shareinview{0}", Commons.StringUtil.GetID_15());
            Commons.FileUtil.GridExportExcel(GridView1, filename);
        }
    }
}